//--------------------Sonic CD HUD Script---------------------//
//--------Scripted by Christian Whitehead 'The Taxman'--------//
//-------Unpacked By Rubberduckycooly's Script Unpacker-------//

// Aliases
// Not all of these are used here in the HUD script, some are just used as a way for other objects to globally transmit values
private alias Object.Value0 : Object.Timer     //	you know this one
private alias Object.Value1 : Object.CameraState     // which cam ur watching
private alias Object.Value2 : Object.Static     // for when an animatronic moves while you watch them

private alias Object.Value7 : Camera.Frame    // Which Camer frame
private alias Object.Value8 : Camera.FrameEnd    // last camera frame

// Game Mode Aliases
public value OfficePower = 100;
public value CameraEnabled = 0;

// Priority
private alias 1 : PRIORITY_ACTIVE

private alias 0  : CAMERA_WAITACTIVATE
private alias 1  : CAMERA_FLIPUP
private alias 2  : CAMERA_MAIN
private alias 99  : CAMERA_EXIT

event ObjectMain
	switch object.State
	case CAMERA_WAITACTIVATE
		if Object[5].Type == TypeName[Blank Object]
			if inputpress.down == 1
				CameraEnabled = 1
				PlaySfx(SfxName[Camera], 0)	
				object.animation = 1
				Camera.Frame = 11
				PowerUsage++
				object.state++
			end if
		end if
	break
	case CAMERA_FLIPUP
		if Camera.Frame == 16
			object.state++
		end if
	break
	case CAMERA_MAIN

		if inputpress.right == 1
			PlaySfx(SfxName[Blip], 0)	
			if Object.CameraState < 11
				Object.CameraState++
			else
				Object.CameraState = 0
			end if
		end if	

		if inputpress.left == 1
			PlaySfx(SfxName[Blip], 0)	
			if Object.CameraState > 0
				Object.CameraState--
			else
				Object.CameraState = 11
			end if
		end if	




		if inputpress.down == 1
			Camera.Frame = 18
			PlaySfx(SfxName[Camera], 0)	
			object.animation = 2
			object.state = CAMERA_EXIT
			PowerUsage--
			CameraEnabled = 0
		end if
	break
	case CAMERA_EXIT
		if Camera.frame == 23
			object.animation = 0
			object.state = 0
		end if
	break
	end switch


	
end event

event ObjectDraw
	// Find the initial X Position to draw the HUD elements

	switch object.animation
	case 0

	break
	case 1

	// This function is used for animating the object, here's a short overview of the values it uses
		// (Frame values are in accordance with SpriteFrames set in ObjectStartup)
		// -> Camera.AnimationSpeed is the speed at which Sonic should animate, it's added to his timer every frame
		// -> Camera.FrameTimer is the timer used for animating Sonic, think of it akin to Object.AnimationTimer
		//     - The next frame is triggered whenever the value is 240 or above, the speed is controlled by Camera.AnimationSpeed
		//     - This doesn't get reset whenever the frame transitions, so keep that in mind too
		// -> Camera.FrameEnd is the final frame of the animation
		// -> Camera.FrameLoop is the loop point for the animation to go back to after reaching its end
		// -> Camera.Frame is the frame to be displayed when drawing the object
		
		// For each animation's corresponding values, check out the ANI_* aliases up above
		
		Object.AnimationTimer += 128
		
		if Object.AnimationTimer > 239
			Object.AnimationTimer -= 240
			
			Camera.Frame++
			if Camera.Frame > 16
				Camera.Frame = 16
			end if
		end if

		DrawSpriteScreenXY(Camera.Frame, screen.xcenter, 190)	//BAR
		if Camera.Frame == 16
			DrawRect(0, 0, screen.xsize, screen.ysize, 0, 0, 0, 255)// 1
		end if

	break
	case 2

	// This function is used for animating the object, here's a short overview of the values it uses
		// (Frame values are in accordance with SpriteFrames set in ObjectStartup)
		// -> Camera.AnimationSpeed is the speed at which Sonic should animate, it's added to his timer every frame
		// -> Camera.FrameTimer is the timer used for animating Sonic, think of it akin to Object.AnimationTimer
		//     - The next frame is triggered whenever the value is 240 or above, the speed is controlled by Camera.AnimationSpeed
		//     - This doesn't get reset whenever the frame transitions, so keep that in mind too
		// -> Camera.FrameEnd is the final frame of the animation
		// -> Camera.FrameLoop is the loop point for the animation to go back to after reaching its end
		// -> Camera.Frame is the frame to be displayed when drawing the object
		
		// For each animation's corresponding values, check out the ANI_* aliases up above
		
		Object.AnimationTimer += 128
		
		if Object.AnimationTimer > 239
			Object.AnimationTimer -= 240
			
			Camera.Frame++
			if Camera.Frame > 23
				Camera.Frame = 23
			end if
		end if

		DrawSpriteScreenXY(Camera.Frame, screen.xcenter, 190)	//BAR

	break	
	end switch

	if object.state == CAMERA_MAIN
		//ui stuff that isnt really important
		//MAP
		temp1 = Screen.xsize
		temp1 -= 160
		DrawSpriteScreenXY(26, temp1, 80)	//MAP

		//draw the button
		//the image is prob gonna be handled above this
		temp1 = Screen.xsize
		temp2 = screen.ysize
		switch Object.CameraState
		case 0
			temp1 -= 115
			temp2 -= 159
		break
		case 1
			temp1 -= 115
		break	
		case 2
			temp1 -= 160
		break			
		case 3
			temp1 -= 131
		break		
		case 4
			temp1 -= 117
		break	
		end switch

		temp3 = Object.CameraState
		temp3 += 27
		DrawSpriteScreenXY(temp3, temp1, temp2)	//MAP


		//OUTLINE
		//top and bottom
		temp0 = screen.xsize
		temp0 -= 8
		DrawRect(4, 4, temp0, 2, color7, color7, color7, 255)// 1
		DrawRect(4, 234, temp0, 2, color7, color7, color7, 255)// 1

		temp0 = screen.ysize
		temp0 -= 10
		DrawRect(4, 4, 2, temp0, color7, color7, color7, 255)// 1

		temp1 = screen.xsize
		temp1 -= 6
		DrawRect(temp1, 4, 2, temp0, color7, color7, color7, 255)// 1
		//red ball	
		DrawSpriteScreenXY(25, 12, 12)	//ba
	end if


	temp1 = screen.xsize
	temp1 -= screen.xcenter
	temp1 -= 150
	DrawSpriteScreenXY(10, temp1, 212)	//BAR
end event


event ObjectStartup
	
	LoadSpriteSheet("FNAF/Camera.gif")
	
	// Place the HUD object into reserved object slot 4 and initialise its values
	Object[6].Type = TypeName[Camera]
	
	// The object should always be run, regardless if it's within camera bounds or not
	Object[6].Priority = PRIORITY_ACTIVE
	
	// Make the HUD draw ontop of all other sprites, too
	Object[6].DrawOrder = 5
	
	// 0-9 - Numbers 0-9
	SpriteFrame(0, 0, 8, 13, 558, 1)
	SpriteFrame(0, 0, 8, 13, 567, 1)
	SpriteFrame(0, 0, 8, 13, 576, 1)
	SpriteFrame(0, 0, 8, 13, 585, 1)
	SpriteFrame(0, 0, 8, 13, 594, 1)
	SpriteFrame(0, 0, 8, 13, 558, 15)
	SpriteFrame(0, 0, 8, 13, 567, 15)
	SpriteFrame(0, 0, 8, 13, 576, 15)
	SpriteFrame(0, 0, 8, 13, 585, 15)
	SpriteFrame(0, 0, 8, 13, 594, 15)

	// 10 - Bar
	SpriteFrame(0, 0, 299, 23, 1, 1)		

	// 11 - camer frames
	SpriteFrame(-220, 15, 459, 36, 1, 25) //11
	SpriteFrame(-240, -25, 487, 76, 1, 62) //12
	SpriteFrame(-270, -90, 540, 166, 1, 139) //13	
	SpriteFrame(-300, -170, 606, 273, 1, 306) //14	
	SpriteFrame(-320, -200, 640, 360, 1, 580) //15
	SpriteFrame(-270, -200, 640, 360, 1, 580) //16	same as 15 but eh

	SpriteFrame(0, 0, 0, 0, 0, 0) //17 BLANK

	//THE SAME ANIMATION BUT BACKWARDS HELP

	SpriteFrame(-320, -200, 640, 360, 1, 580) //18
	SpriteFrame(-300, -170, 606, 273, 1, 306) //19	
	SpriteFrame(-270, -90, 540, 166, 1, 139) //20	
	SpriteFrame(-240, -25, 487, 76, 1, 62) //21
	SpriteFrame(-220, 15, 459, 36, 1, 25) //22
	SpriteFrame(-220, 15, 459, 36, 1, 25) //23 clone

	//old map idk what to do with it	24
	SpriteFrame(0, 0, 200, 172, 823, 851) //24 map big
	//25
	SpriteFrame(0, 0, 24, 24, 889, 1) //25 red baller	
	//26
	SpriteFrame(0, 0, 146, 124, 877, 726) //26 map small


	//LIT BUTTONS
	SpriteFrame(0, 0, 22, 15, 775, 727) //27	1A showstage
	SpriteFrame(0, 0, 22, 15, 775, 749) //28	1B	dining room
	SpriteFrame(0, 0, 22, 15, 730, 757) //29	5	Backstage
	SpriteFrame(0, 0, 22, 15, 759, 778) //30	1C	Foxy Land
	SpriteFrame(0, 0, 22, 15, 773, 806) //31	2A	West Hall	
	SpriteFrame(0, 0, 22, 15, 745, 811) //32	3A	Closet

	SpriteFrame(0, 0, 22, 15, 773, 806) //33	2B	W Hall Corner
	SpriteFrame(0, 0, 22, 15, 773, 806) //34	4A	East Hall
	SpriteFrame(0, 0, 22, 15, 773, 806) //35	4B	E Hall Corner
	SpriteFrame(0, 0, 22, 15, 773, 806) //36	6	Kitchen
	SpriteFrame(0, 0, 22, 15, 773, 806) //37	7	Bathrooms	


end event


// ========================
// Editor events
// ========================

event RSDKDraw
	DrawSprite(0)
end event


event RSDKLoad
	LoadSpriteSheet("3D_Test/Objects.gif")
	SpriteFrame(0, 0, 24, 16, 206, 58)

	SetVariableAlias(ALIAS_VAR_PROPVAL, "unused")
end event
